import { ref } from 'vue'
import { adapter, request } from '@/request'
import { checkOnlineActivityByGet } from '@/core/api/promotion'
import type { RequestWrapper } from '@/core/interfaces/common'
import type { Activity } from '@/core/interfaces/activity'
import type { Order } from '@/core/interfaces/order'
import { type GiftKindEnum } from '@/views/promotion/interface'

interface Params {
  type: Activity['type']
  orderId: Order['id']
  giftType: GiftKindEnum
}

export interface OnlineActivityInfo {
  wordNum: number
  combinedWordNum: number
  combinedWordNumSum?: number
  wordNumSum?: number
  pcNumber?: number
  wapNumber?: number
}

export default function checkOnlineActivity() {
  const service = adapter<RequestWrapper<OnlineActivityInfo>>(request)
  const loading = ref(false)
  const response = ref<Partial<OnlineActivityInfo>>({})

  const fetch = (params: Params) => {
    const { url, method } = checkOnlineActivityByGet()
    loading.value = true

    return service({
      config: {
        url,
        method,
        params
      },
      callback: (res) => {
        response.value = res.data.data
      },
      error: (err) => {
        console.log(err)
      },
      done: () => {
        loading.value = false
      }
    })
  }

  return [null, fetch, loading] as const
}
